//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package wudashan.Protocol;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class CmdProcess {
    private String identifier = "123";
    private String msgType = "deviceReq";
    private String serviceId = "Brightness";
    private String cmd = "SET_DEVICE_LEVEL";
    private int hasMore = 0;
    private int errcode = 0;
    private int mId = 0;
    private JsonNode paras;

    public CmdProcess() {
    }

    public CmdProcess(ObjectNode input) {
        try {
            this.identifier = input.get("identifier").asText();
            this.msgType = input.get("msgType").asText();
            if (this.msgType.equals("cloudRsp")) {
                this.errcode = input.get("errcode").asInt();
                this.hasMore = input.get("hasMore").asInt();
                return;
            }

            this.mId = input.get("mId").intValue();
            this.cmd = input.get("cmd").asText();
            this.paras = input.get("paras");
            this.hasMore = input.get("hasMore").asInt();
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }

    public byte[] toByte() {
        try {
            if (this.msgType.equals("cloudReq")) {
                if (this.cmd.equals("SET_DEVICE_LEVEL")) {
                    int brightlevel = this.paras.get("value").asInt();
                    byte[] byteRead = new byte[]{-86, 114, (byte)brightlevel, 0, 0};
                    byte[] byteMid = new byte[2];
                    byteMid = this.int2Bytes(this.mId, 2);
                    byteRead[3] = byteMid[0];
                    byteRead[4] = byteMid[1];
                    return byteRead;
                }
            } else if (this.msgType.equals("cloudRsp")) {
                byte[] ack = new byte[]{-86, -86, (byte)this.errcode, (byte)this.hasMore};
                return ack;
            }

            return null;
        } catch (Exception var4) {
            var4.printStackTrace();
            return null;
        }
    }

    public byte[] int2Bytes(int value, int len) {
        byte[] b = new byte[len];

        for(int i = 0; i < len; ++i) {
            b[len - i - 1] = (byte)(value >> 8 * i);
        }

        return b;
    }
}
